/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utilities.entities;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author olawale
 */
public class XDate {

    public XDate(int y, int m, int d, int dy){
        year = y;
        month = m;
        date = d;
        day = dy;
    }

    public XDate(Date date){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH);
        this.date = cal.get(Calendar.DATE);
        day = cal.get(Calendar.DAY_OF_WEEK);
    }

    @Override
    public String toString() {
        String ddd = days[day] + ", " + date + " " + months[month] + " " + year;
        return ddd;
    }

    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof XDate)){
            return false;
        }
        XDate other = (XDate) obj;
        if((this.date == other.date) && (this.day == other.day) &&
                (this.month == other.month) && (this.year == other.year)){
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + this.year;
        hash = 67 * hash + this.month;
        hash = 67 * hash + this.date;
        return hash;
    }

    

    public XDate addWeek(){
        date = date + 7;
        return this;
    }

    private static String [] days = {"", "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
    private static String [] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    private int year;
    private int month;
    private int date;
    public int day;

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDate() {
        return date;
    }

    public void setDate(int date) {
        this.date = date;
    }

    public static XDate getXDate(Date date){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int d = cal.get(Calendar.DATE);
        int dy = cal.get(Calendar.DAY_OF_WEEK);
        XDate xdate = new XDate(y, m, d, dy);
        return xdate;
    }

    public static Date getDate(XDate xdate){
        Calendar cal = Calendar.getInstance();
        int y = xdate.getYear();
        int m = xdate.getMonth();
        int d = xdate.getDate();
        cal.set(y, m, d);
        return cal.getTime();
    }

}
